import {
	orderBuy,
} from '@/api/order'

export async function createOrder(e) {
	uni.showLoading({
		title: '加载中'
	});
	
	let {
		code,
		data
	} = await orderBuy({
		action: 'submit',
		item_id: e.id
	});
	if(code == 1){
		uni.hideLoading();
		uni.$on('payment', (params) => {
			setTimeout(() => {
				uni.$off('payment')

				if (params.result) {
					uni.redirectTo({
						url: `/pages/pay_result/pay_result?id=${params.order_id}`
					})
				} else {
					uni.redirectTo({
						url: '/pages/user_order/user_order'
					})
				}
			}, 500)
		})
		uni.redirectTo({
			url: `/pages/payment/payment?from=${data.type}&order_id=${data.order_id}`
		})
	}
}